﻿using System.ComponentModel;
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace WPFExcelReport
{
    public partial class K8872
    {
        public K8872()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            InitializeComponent();
            SDSA = "8872";
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded) return;
            base.Window_Loaded(sender, e);
            // LOADALL();
            NormalTask = Task.Factory.StartNew(() => LOADALL(), new CancellationTokenSource().Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
        public override void LOADALL()
        {
            base.LOADALL();
            if (SDSA.Length == 0) return;
            foreach (DataRow row in TBMain.Rows)
            {
                row["SDES"] = Helpers.Helper.Convert8859P1ToGB2312(row["SDES"].ToString().Trim());
                row["DES"] = Helpers.Helper.Convert8859P1ToGB2312(row["DES"].ToString().Trim());
            }
            if (TBMain.Rows.Count > 0)
                return;
            if (DBSDDAT.ContainsKey(SDSA))
            {
                DBSDDAT.Remove(SDSA);
            }
            dwData = TBMain.NewRow();
            TMV.SetUpNewRow(ref dwData, SDSA);
            dwData["KEY"] = "01";
            dwData["DES"] = Helpers.Helper.ConvertGB2312To8859P1("全部");
            dwData["SDES"] = Helpers.Helper.ConvertGB2312To8859P1("全部");
            dwData["VALUE"] = "000000000";
            TMV.Save(dwData);

            dwData["KEY"] = "02";
            dwData["DES"] = Helpers.Helper.ConvertGB2312To8859P1("待复板");
            dwData["SDES"] = Helpers.Helper.ConvertGB2312To8859P1("待复板");
            dwData["VALUE"] = "000000000";
            TMV.Save(dwData);

            dwData["KEY"] = "03";
            dwData["DES"] = Helpers.Helper.ConvertGB2312To8859P1("已启动");
            dwData["SDES"] = Helpers.Helper.ConvertGB2312To8859P1("已启动");
            dwData["VALUE"] = "000000000";
            TMV.Save(dwData);

            dwData["KEY"] = "04";
            dwData["DES"] = Helpers.Helper.ConvertGB2312To8859P1("已确认");
            dwData["SDES"] = Helpers.Helper.ConvertGB2312To8859P1("已确认");
            dwData["VALUE"] = "000000000";
            TMV.Save(dwData);

            dwData["KEY"] = "05";
            dwData["DES"] = Helpers.Helper.ConvertGB2312To8859P1("已投料");
            dwData["SDES"] = Helpers.Helper.ConvertGB2312To8859P1("已投料");
            dwData["VALUE"] = "000000000";
            TMV.Save(dwData);
            LOADALL();
        } 
    }
}
